import { cachesStorage } from '../../core/utils/modules/cachesUtils'
import config from '../../core/config'
const user = {
    state: {
        token: cachesStorage('token', 'get'),
        userInfo: cachesStorage('userInfo', 'get'),
        imgPrefix: process.env.NODE_ENV === 'development' ? config.imgPrefix.dev : config.imgPrefix.pro
    },
    mutations: {
        /**
         * 设置用户信息
         * @param state
         * @param userInfo
         * @constructor
         */
        SET_USER_INFO (state, userInfo) {
            state.userInfo = userInfo
            cachesStorage('userInfo', 'set', userInfo)
        },
        /**
         * 清楚用户信息
         * @param state
         * @constructor
         */
        CLEAR_USER_INFO (state) {
            state.userInfo = false
            cachesStorage('userInfo', 'clear')
        },
        /**
         * 设置token
         * @param state
         * @param token
         * @constructor
         */
        SET_TOKEN (state, token) {
            state.token = token
            cachesStorage('token', 'set', token)
        },
        /**
         * 清除token
         * @param state
         * @constructor
         */
        CLEAR_TOKEN (state) {
            state.token = false
            cachesStorage('token', 'clear')
        },
        /**
         * 退出登录
         * @param state
         * @constructor
         */
        LOGIN_OUT (state) {
            state.token = false
            state.userInfo = false
            cachesStorage('token', 'clear')
            cachesStorage('userInfo', 'clear')
        },
    },
    actions: {

    }
}

export default user
